package com.apes.scm.rbac.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * Created by lishikun on 2021/5/11 11:31
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PersonalMenuMark.CONST_TABLE_NAME)
public class PersonalMenuMark extends Model {
    public static final String CONST_TABLE_NAME = "aut_personal_menu_mark";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "个人菜单标记")
    private String id;


    @ManyToOne(fetch = FetchType.LAZY)
    @Comment("菜单")
    @JoinColumn(name = "menu_id", referencedColumnName = "id", nullable = false)
    private Menu menu;

    @ManyToOne(fetch = FetchType.LAZY)
    @Comment("岗位")
    @JoinColumn(name = "post_id", referencedColumnName = "id", nullable = false)
    private Post post; //岗位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false)
    private User user; //用户

    @Column(name = "mark", nullable = false,columnDefinition = "number(1,0) default 0")
    @Comment("标记")
    private Boolean mark = false;

    @Transient
    private String menuPath;

    public String getMenuPath() {
        return menu.getPath();
    }

}
